using System;
using System.Collections.Generic;
using System.Text;
using DAL;
using DTO;
using System.Data;
using System.Data.OleDb;
namespace BLL
{
    public class SinhvienDAL
    {
        public List<SINHVIEN> GetAll()
        {
            SINHVIEN sinhvien;
            List<SINHVIEN> list = new List<SINHVIEN>();
            DataProvider dataprovider = new DataProvider();
            DataTable datatable = new DataTable();
            datatable = dataprovider.ExecuteSelectQuery("Select * from SINHVIEN", null);
            for (int i = 0; i < datatable.Rows.Count; i++)
            {
                sinhvien = new SINHVIEN();
                sinhvien.MaSV = datatable.Rows[i]["MaSV"].ToString();
                sinhvien.Holot = datatable.Rows[i]["Holot"].ToString();
                sinhvien.Ten = datatable.Rows[i]["Ten"].ToString();
                list.Add(sinhvien);
            }
            return list;
        }

        public SINHVIEN GetSINHVIEN(Int32 masv)
        {
            DataProvider dataprovider = new DataProvider();
            OleDbParameter[] parameters = new OleDbParameter[1];
            parameters[0] = new OleDbParameter("@masv", OleDbType.Integer);
            parameters[0].Value = masv;
            DataTable datatable = new DataTable();
            datatable = dataprovider.ExecuteSelectQuery("Select * from SINHVIEN where MaSV = @masv", parameters);
            SINHVIEN sinhvien = new SINHVIEN();
            if (datatable.Rows.Count != 0)
            {
                sinhvien.MaSV = datatable.Rows[0]["MaSV"].ToString();
                sinhvien.Holot = datatable.Rows[0]["Holot"].ToString();
                sinhvien.Ten = datatable.Rows[0]["Ten"].ToString();
                return sinhvien;
            }
            else
                return null;
        }

        public bool UpdateSINHVIEN(byte masv, string holot, string ten, byte masvcu)
        {
            DataProvider dataprovider = new DataProvider();
            OleDbParameter[] parameters = new OleDbParameter[3];
            parameters[0] = new OleDbParameter("@masv", OleDbType.Integer);
            parameters[0].Value = masv;
            parameters[1] = new OleDbParameter("@holot", OleDbType.Char);
            parameters[1].Value = holot;
            parameters[2] = new OleDbParameter("@ten", OleDbType.Char);
            parameters[2].Value = ten;
            parameters[3] = new OleDbParameter("@masvcu", OleDbType.Integer);
            parameters[3].Value = masvcu;
            return dataprovider.ExecuteNonSelectQuery("update SINHVIEN set MaSV=@masv, Holot=@holot, Ten=@ten, where MaSV = @masvcu", parameters);
        }

        public bool UpdateSINHVIEN(byte p, string p_2, string p_3)
        {
            throw new Exception("The method or operation is not implemented.");
        }
    }
}

    

